package com.Collections;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

public class CollectionsTest {
    public static void main(String[] args) {
        //创建单列集合：List
        ArrayList<Integer> list = new ArrayList<>();

        //添加：
        Collections.addAll(list,1,2,3,4,5,6,7);

        //默认排序：
        Collections.sort(list);
        System.out.println(list);
        System.out.println("---------------------");

        System.out.println(Collections.binarySearch(list,3));
        System.out.println("--------------------------------------");

        //根据指定规则排序:
        Collections.sort(list, new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o2 - o1;
            }
        });

        System.out.println(list);
        System.out.println("---------------------");

        // 先确保 dest 有足够的容量
        ArrayList<Integer> dest = new ArrayList<>(list.size());
// 填充元素以确保有足够的位置
        for(int i = 0; i < list.size(); i++) {
            dest.add(0); // 添加占位元素
        }
        Collections.copy(dest, list); // 注意参数顺序：目标在前，源在后
        System.out.println(dest);

        Collections.copy(list,dest);
        System.out.println(dest);
        System.out.println("---------------------");

        System.out.println(Collections.max( list));
        System.out.println("-------------------");

        Collections.swap(list,0,2);
        System.out.println(list);
        System.out.println("-------------------");







        Collections.fill(list, 0);
        System.out.println(list);










    }
}
